﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace SafeLoad.NControl.Converter
{
  public class InfoStyleConverter : IValueConverter
  {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
      if (!System.Convert.ToBoolean(parameter))
      {
        return System.Convert.ToBoolean(value) ? Visibility.Visible : Visibility.Hidden;
      }
      else
      {
        return System.Convert.ToBoolean(value) ? Visibility.Hidden : Visibility.Visible;
      }
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
      return ((Visibility)value == Visibility.Visible) ? true : false;
    }
  }

  public class InfoDateConverter : IValueConverter
  {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
      DateTime dt = System.Convert.ToDateTime(value);
      if (dt.Equals(DateTime.MinValue))
      {
        return "----";
      }
      else
      {
        return dt.ToString("yyyy-MM-dd");
      }
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
      throw new NotImplementedException();
    }
  }

  public class InfoTimeConverter : IValueConverter
  {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
      DateTime dt = System.Convert.ToDateTime(value);
      if (dt.Equals(DateTime.MinValue))
      {
        return "----";
      }
      else
      {
        return dt.ToString("HH:mm:ss");
      }
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
      throw new NotImplementedException();
    }
  }
}
